
// 根据商品名称模糊查询
export const getCommodityByKeyword = (keyword) => {
  return new Promise((resolve, reject) => {
    uni.request({
      url: `http://43.136.172.73/api/v1/commodity/like?keyword=${encodeURIComponent(keyword)}`,//接收一个 keyword 参数，用于指定商品名称的模糊查询关键词。
	  header:{
	  		  Authorization:'sfsdf'
	  },
      method: 'GET',
      success: (res) => {
        resolve(res.data);
      },
      fail: (err) => {
        reject(err);
      },
    });
  });
}

// 根据商品id查询商品详情
export const getCommodityDetail = (id) => {
  return new Promise((resolve, reject) => {
    uni.request({
      url: `http://43.136.172.73/api/v1/commodity/${id}`,
	  header:{
	  		  Authorization:'sfsdf'
	  },
      method: 'GET',
      success: (res) => {
        resolve(res.data);
      },
      fail: (err) => {
        reject(err);
      },
    });
  });
};

// 根据商品分类id查询商品列表
/* export const getCommodityListByCategoryId = (categoryId) => {
  return new Promise((resolve, reject) => {
    uni.request({
      url: `http://43.136.172.73/api/v1/commodity/${categoryId}`,
	  header:{
	  		  Authorization:'sfsdf'
	  },
      method: 'GET',
      success: (res) => {
        resolve(res.data);
      },
      fail: (err) => {
        reject(err);
      },
    });
  }); 
};*/

// 获取商品分类列表
export const getCommodityCategoryList = () => {
  return new Promise((resolve, reject) => {
    uni.request({
      url: 'http://43.136.172.73/api/v1/commodity/category/list',
	  header:{
	  		  Authorization:'sfsdf'
	  },
      method: 'GET',
      success: (res) => {
        resolve(res.data);
      },
      fail: (err) => {
        reject(err);
      },
    });
  });
};
// 查询商品列表
export const getCommodityList = () => {
  return new Promise((resolve, reject) => {
    uni.request({
      url: 'http://43.136.172.73/api/v1/commodity/list',
	  header:{
		  Authorization:'sfsdf'
	  },
      method: 'GET',
      success: (res) => {
        resolve(res.data);
      },
      fail: (err) => {
        reject(err);
      },
    });
  });
};

// 根据名称查询商品列表
export function getCommodityListByName(name) {
  return new Promise((resolve, reject) => {
    uni.request({
      url: `http://43.136.172.73/api/v1/commodity/category/name/${name}`,
	  data:name,
	  header:{
		  'Authorization':'sfsdf'
	  },
      method: 'GET',
      success: (res) => {
        resolve(res.data);
      },
      fail: (err) => {
        reject(err);
      },
    });
  });
};
